#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

bool dfs(int n,int m) {
	if (n == m) return 1;
	if (n % 3 != 0) return 0;
	return dfs(n / 3, m) || dfs(n / 3 * 2, m);
}

void solve() {
	int n, m; cin >> n >> m;
	cout << (dfs(n, m) ? "YES" : "NO") << endl;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}